package com.yskj.mwk.controller;

import com.yskj.mwk.bean.OrderDescMa;
import com.yskj.mwk.bean.Supplier;
import com.yskj.mwk.service.ManagerService;
import com.yskj.mwk.utils.JsonResult;
import com.yskj.mwk.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;
    /**
     *登录后台
     * utype=0管理
     * utype=1普通租户
     * */
    @PostMapping("login_ma")
    public JsonResult loginManager(@RequestParam int type,@RequestParam String tell,@RequestParam String pwd){
        try {
            Supplier supplier = managerService.loginManager(type,tell,pwd);
            if(supplier!=null){
                return ResultUtils.success("登录成功",supplier);
            }else{
                return  ResultUtils.failure(101,"账号或密码错误");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取首页数据
     * 头部四方格
     * */
    @PostMapping("getIndexTopData")
    public JsonResult getIndexTopData(@RequestParam int accountType,@RequestParam int accountId){
        try {
            List<Map<String, Object>> lists = managerService.getIndexTopData(accountType,accountId);
            return ResultUtils.success("获取成功",lists);
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取首页 销售趋势 echart数据
     * */
    @PostMapping("getIndexLeftData")
    public JsonResult getIndexLeftData(@RequestParam int accountType,@RequestParam int accountId){
        try {
            Map<String, Object> map = managerService.getIndexLeftData(accountType,accountId);
            return ResultUtils.success("获取成功",map);
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取首页 订单状态 echart数据
     * */
    @PostMapping("getIndexRightData")
    public JsonResult getIndexRightData(@RequestParam int accountType,@RequestParam int accountId){
        try {
            Map<String, Integer> map= managerService.getIndexRightData(accountType,accountId);
            return ResultUtils.success("获取成功",map);
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取首页 订单状态 echart数据
     * */
    @PostMapping("getIndexBottomData")
    public JsonResult getIndexBottomData(@RequestParam int accountType,@RequestParam int accountId,@RequestParam String searchMonth){
        try {
            Map<String, Object> map= managerService.getIndexBottomData(accountType,accountId,searchMonth);
            return ResultUtils.success("获取成功",map);
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取租户列表
     * 昵称筛选
     * */
    @PostMapping("getSuppliersByPage")
    public JsonResult getSuppliersByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam("name") String name){
        try {
            return  ResultUtils.success("获取成功",managerService.getSuppliersByPage(name,pageNum,pageSize));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 新增租户
     * */
    @PostMapping("addSupplier")
    public JsonResult addSupplier(@RequestParam("supplierId") int supplierId,@RequestParam("supplierName") String supplierName,@RequestParam("supplierPhone") String supplierPhone,@RequestParam("supplierPwd") String supplierPwd,@RequestParam("supplierType") int supplierType,@RequestParam("supplierAddress") String supplierAddress,@RequestParam("supplierLxr") String supplierLxr){
        try {
            int res=managerService.addSupplier(supplierId,supplierName,supplierPhone,supplierPwd,supplierType,supplierAddress,supplierLxr);
            if(res>0){
                return  ResultUtils.success("获取成功",null);
            }else{
                return  ResultUtils.failure(101,"获取失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 根据id获取租户详情
     * */
    @PostMapping("getSupplierDescById")
    public JsonResult getSupplierDescById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("获取成功",managerService.getSupplierDescById(id));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取租户列表
     * 昵称筛选
     * */
    @PostMapping("getUsersByPage")
    public JsonResult getUsersByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam("name") String name,@RequestParam("tell") String tell){
        try {
            return  ResultUtils.success("获取成功",managerService.getUsersByPage(name,tell,pageNum,pageSize));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取订单
     * */
    @PostMapping("getOrdersByPage")
    public JsonResult getOrdersByPage(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam("accountType") int accountType,
            @RequestParam("accountId") int accountId,
            @RequestParam("orderId") String orderId,
            @RequestParam("orderTime1") String orderTime1,
            @RequestParam("orderTime2") String orderTime2,
            @RequestParam("orderStatus") String orderStatus,
            @RequestParam("getPdfTime1") String getPdfTime1,
            @RequestParam("getPdfTime2") String getPdfTime2,
            @RequestParam("downloadTime1") String downloadTime1,
            @RequestParam("downloadTime2") String downloadTime2,
            @RequestParam("isDownload") String isDownload,
            @RequestParam("trackingNo") String trackingNo
    ){
        try {
            int ostate=0;
            if (orderStatus.isEmpty()){
                ostate=0;
            }else{
                ostate=Integer.parseInt(orderStatus);
            }
            return  ResultUtils.success("获取成功",managerService.getOrdersByPage(pageNum,pageSize,accountType,accountId,orderId,ostate,orderTime1,orderTime2,getPdfTime1,getPdfTime2,downloadTime1,downloadTime2,isDownload,trackingNo));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取订单详情
     * */
    @PostMapping("getOrdersDescList")
    public JsonResult getOrdersDescList(@RequestParam("orderId") String orderId){
        try {
            return  ResultUtils.success("获取成功",managerService.getOrdersDescList(orderId));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取分类
     * parentId=0 一级分类
     * */
    @PostMapping("getSortByPage")
    public JsonResult getSortByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam("parentId") int parentId){
        try {
            return  ResultUtils.success("获取成功",managerService.getSortByPage(pageNum,pageSize,parentId));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除分类
     * */
    @PostMapping("deleteSortById")
    public JsonResult deleteSortById(@RequestParam("id") int id){
        try {
            int res=managerService.deleteSortById(id);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 修改分类显示状态
     * */
    @PostMapping("updateSortStatusById")
    public JsonResult updateSortStatusById(@RequestParam("id") int id,@RequestParam("isShow") int isShow){
        try {
            int res=managerService.updateSortStatusById(id,isShow);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 添加分类
     *修改
     * */
    @PostMapping("addSort")
    public JsonResult addSort(@RequestParam("iconPic") String iconPic,@RequestParam("name") String name,@RequestParam("isShow") int isShow,@RequestParam("level") int level,@RequestParam("parentId") int parentId,@RequestParam("type") int type,@RequestParam("id") int id){
        try {
            int res=managerService.addSort(iconPic,name,isShow,level,parentId,type,id);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取分类详情
     * */
    @PostMapping("getSortDescById")
    public JsonResult getSortDescById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("操作成功",managerService.getSortDescById(id));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取商品的利润
     * 筛选日期
     * */
    @PostMapping("getGoodsSpuSalePageByTime")
    public JsonResult getGoodsSpuSalePageByTime(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime,@RequestParam("spuName") String spuName,@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsSpuSalePageByTime(startTime,endTime,spuName,pageNum,pageSize));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取商品列表
     * */
    @PostMapping("getGoodsPage")
    public JsonResult getGoodsPage(
            @RequestParam("spuName") String spuName,
            @RequestParam("sort2Id") String sort2Id,
            @RequestParam("publishStatus") String publishStatus,
            @RequestParam("supplierId") String supplierId,
            @RequestParam("isDiy") String isDiy,
            @RequestParam("isPopular") String isPopular,
            @RequestParam("isNew") String isNew,
            @RequestParam("isMiaosha") String isMiaosha,
            @RequestParam("isJingxuan") String isJingxuan,
            @RequestParam("level") int level,
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize){
        try {
            int sort2Id_int=0;
            if(!sort2Id.isEmpty()){
                sort2Id_int=Integer.parseInt(sort2Id);
            }
            int publishStatus_int=-1;
            if(!publishStatus.isEmpty()){
                publishStatus_int=Integer.parseInt(publishStatus);
            }
            int supplierId_int=0;
            if(!supplierId.isEmpty()){
                supplierId_int=Integer.parseInt(supplierId);
            }
            int isDiy_int=-1;
            if(!isDiy.isEmpty()){
                isDiy_int=Integer.parseInt(isDiy);
            }
            int isPopular_int=-1;
            if(!isPopular.isEmpty()){
                isPopular_int=Integer.parseInt(isPopular);
            }
            int isNew_int=-1;
            if(!isNew.isEmpty()){
                isNew_int=Integer.parseInt(isNew);
            }
            int isJingxuan_int=-1;
            if(!isJingxuan.isEmpty()){
                isJingxuan_int=Integer.parseInt(isJingxuan);
            }
            int isMiaosha_int=-1;
            if(!isMiaosha.isEmpty()){
                isMiaosha_int=Integer.parseInt(isMiaosha);
            }
            return  ResultUtils.success("操作成功",managerService.getGoodsPage(spuName, sort2Id_int, publishStatus_int, supplierId_int, isDiy_int, isPopular_int, isNew_int, level, pageNum, pageSize,isJingxuan_int,isMiaosha_int));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取租户列表不分页
     * */
    @PostMapping("getAllSuppliers")
    public JsonResult getAllSuppliers(@RequestParam("supplierName") String supplierName){
        try {
            return  ResultUtils.success("操作成功",managerService.getAllSuppliers(supplierName));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取分类
     * */
    @PostMapping("getAllSorts")
    public JsonResult getAllSorts(@RequestParam("parentId") int parentId){
        try {
            return  ResultUtils.success("操作成功",managerService.getAllSorts(parentId));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取商品表主体详情
     * */
    @PostMapping("getGoodsById")
    public JsonResult getGoodsById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsById(id));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 添加商品
     * */
    @PostMapping("addGoods")
    public JsonResult addGoods(
            @RequestParam("spuId") Integer spuId,
            @RequestParam("spuName") String spuName,
            @RequestParam("spuDesc") String spuDesc,
            @RequestParam("sort1Id") Integer sort1Id,
            @RequestParam("sort2Id") Integer sort2Id,
            @RequestParam("supplierId") Integer supplierId,
            @RequestParam("publishStatus") Integer publishStatus,
            @RequestParam("isNew") Integer isNew,
            @RequestParam("isPopular") Integer isPopular,
            @RequestParam("isDiy") Integer isDiy,
            @RequestParam("level") Integer level,
            @RequestParam("minNum") Integer minNum,
            @RequestParam("price") Double price,
            @RequestParam("sourceId") Integer sourceId,
            @RequestParam("isMiaosha") Integer isMiaosha,
            @RequestParam("isJingxuan") Integer isJingxuan,
            @RequestParam("isMatting") Integer isMatting,
            @RequestParam("isTwo") Integer isTwo
    ){
        try {
            int res=managerService.addGoods(spuId,spuName,spuDesc,sort1Id,sort2Id,supplierId,publishStatus,isNew,isPopular,isDiy,level,minNum,price,sourceId,isJingxuan,isMiaosha,isMatting,isTwo);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取商品所有图片
     * */
    @PostMapping("getGoodsImageList")
    public JsonResult getGoodsImageList(@RequestParam("id") int id,@RequestParam("type") int type){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsImageList(id,type));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 编辑商品图片
     * 或新增
     * */
    @PostMapping("addGoodsImage")
    public JsonResult addGoodsImage(@RequestParam("id") int id,@RequestParam("type") int type,@RequestParam("level") int level,@RequestParam("spuId") int spuId,@RequestParam("picUrl") String picUrl){
        try {
            int res=managerService.addGoodsImage(id,type,level,spuId,picUrl);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除图片
     * */
    @PostMapping("delGoodsImage")
    public JsonResult delGoodsImage(@RequestParam("id") int id){
        try {
            int res=managerService.delGoodsImage(id);
            if(res>0){
                return  ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取商品图片对象
     * */
    @PostMapping("getGoodsImageById")
    public JsonResult getGoodsImageById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsImageById(id));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取获取sku列表
     * */
    @PostMapping("getGoodsSkuList")
    public JsonResult getGoodsSkuList(@RequestParam("id") int id,@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsSkuList(id,pageNum,pageSize));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 批量修改sku详细信息
     * */
    @PostMapping("editGoodsSku")
    public JsonResult editGoodsSku(@RequestParam("ids") String ids,@RequestParam("salesPrice") double salesPrice,@RequestParam("underlinedPrice") double underlinedPrice,@RequestParam("costPrice") double costPrice,@RequestParam("enable") int enable,@RequestParam("skuPic") String skuPic,@RequestParam("stock") int stock){
        try {
            int res=managerService.editGoodsSku(ids,salesPrice,underlinedPrice,costPrice,enable,skuPic,stock);
            if (res>0){
                return ResultUtils.success("操作成功",null);
            }else{
                return ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取sku详情
     * */
    @PostMapping("getGoodsSkuDescById")
    public JsonResult getGoodsSkuDescById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsSkuDescById(id));
        }catch (Exception e){
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取spu规格信息
     * */
    @PostMapping("getGoodsSpecById")
    public JsonResult getGoodsSpecById(@RequestParam("id") int id){
        try {
            return  ResultUtils.success("操作成功",managerService.getGoodsSpecById(id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 修改或者新增
     * */
    @PostMapping("updateGoodsSpec")
    public JsonResult updateGoodsSpec(@RequestParam("id") int id,@RequestParam("spec_template") String spec_template){
        try {
            return  ResultUtils.success("操作成功",managerService.updateGoodsSpec(id,spec_template));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 修改或新增租户的物流配置
     * */
    @PostMapping("editSupplierWuliuConfig")
    public JsonResult editSupplierWuliuConfig(
            @RequestParam("supplierId") int supplierId,
            @RequestParam("jt_apiAccount") String jt_apiAccount,
            @RequestParam("jt_privateKey") String jt_privateKey,
            @RequestParam("jt_customerCode") String jt_customerCode,
            @RequestParam("jt_orderPassword") String jt_orderPassword,
            @RequestParam("sendAddress") String sendAddress,
            @RequestParam("sendName") String sendName,
            @RequestParam("sendTell") String sendTell,
            @RequestParam("sendProv") String sendProv,
            @RequestParam("sendCity") String sendCity,
            @RequestParam("sendArea") String sendArea){
        try {
            int res=managerService.editSupplierWuliuConfig(supplierId,jt_apiAccount,jt_privateKey,jt_customerCode,jt_orderPassword,sendAddress,sendName,sendTell,sendProv,sendCity,sendArea);
            if (res>0){
                return ResultUtils.success("操作成功",null);
            }else{
                return ResultUtils.failure(101,"操作失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取物流配置信息
     * */
    @PostMapping("getSupplierWuliuConfig")
    public JsonResult getSupplierWuliuConfig(@RequestParam("supplierId") int supplierId){
        try {
            return ResultUtils.success("操作成功",managerService.getSupplierWuliuConfig(supplierId));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取模板图片的资源包
     * 用于管理产品
     * */
    @PostMapping("getTemplatePackageByPage")
    public JsonResult getTemplatePackageByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize){
        try {
            return ResultUtils.success("操作成功",managerService.getTemplatePackageByPage(pageNum,pageSize));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 新增或编辑模板图片分类
     * */
    @PostMapping("editTemplatePackageByPage")
    public JsonResult editTemplatePackageByPage(@RequestParam("name") String name,@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.editTemplatePackageByPage(name,id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除模板图片的资源包
     * */
    @PostMapping("delTemplatePackage")
    public JsonResult delTemplatePackage(@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.delTemplatePackage(id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取模板图片分类 分页
     * */
    @PostMapping("getTemplateImageByPage")
    public JsonResult getTemplateImageByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam("parentId") int parentId,@RequestParam("type") int type){
        try {
            return ResultUtils.success("操作成功",managerService.getTemplateImageByPage(pageNum,pageSize,parentId,type));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 新增或编辑模板图片分类
     * */
    @PostMapping("editTemplateImageByPage")
    public JsonResult editTemplateImageByPage(@RequestParam("sortName") String sortName,@RequestParam("isShow") int isShow,@RequestParam("level") int level,@RequestParam("id") int id,@RequestParam("parentId") int parentId,@RequestParam("type") int type){
        try {
            return ResultUtils.success("操作成功",managerService.editTemplateImageByPage(sortName,isShow,level,id,parentId,type));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除模板图片分类
     * */
    @PostMapping("delTemplateImageByPage")
    public JsonResult delTemplateImageByPage(@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.delTemplateImageByPage(id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 修改状态模板图片分类
     * */
    @PostMapping("updateTemplateImageSortStatus")
    public JsonResult updateTemplateImageSortStatus(@RequestParam("isShow") int isShow,@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.updateTemplateImageSortStatus(isShow,id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取模板图片 分页
     * */
    @PostMapping("getTempImageByPage")
    public JsonResult getTempImageByPage(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam("sortId") int sortId,@RequestParam("type") int type){
        try {
            return ResultUtils.success("操作成功",managerService.getTempImageByPage(pageNum,pageSize,sortId,type));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 获取资源包
     * */
    @PostMapping("getTemplatePackages")
    public JsonResult getTemplatePackages(){
        try {
            return ResultUtils.success("操作成功",managerService.getTemplatePackages());
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 新增或编辑模板图片分类
     * */
    @PostMapping("editTempImage")
    public JsonResult editTempImage(@RequestParam("templatePic") String templatePic,@RequestParam("sortId") int sortId,@RequestParam("level") int level,@RequestParam("id") int id,@RequestParam("type") int type){
        try {
            return ResultUtils.success("操作成功",managerService.editTempImage(templatePic,sortId,level,id,type));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除模板图片分类
     * */
    @PostMapping("delTempImage")
    public JsonResult delTempImage(@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.delTempImage(id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 删除模板图片详情
     * */
    @PostMapping("getTempImageDesc")
    public JsonResult getTempImageDesc(@RequestParam("id") int id){
        try {
            return ResultUtils.success("操作成功",managerService.getTempImageDesc(id));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 生成一个pdf文件
     * */
    @PostMapping("downloadPdf")
    public JsonResult downloadPdf(HttpServletRequest request, @RequestParam("orderId") String orderId){
        try {
            return ResultUtils.success("操作成功",managerService.downloadPdf(request.getRequestURL().toString(),orderId));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 保存首页广告营销图
     * */
    @PostMapping("saveIndexMarketingPoster")
    public JsonResult saveIndexMarketingPoster(@RequestParam("imageUrl") String imageUrl){
        try {
            return ResultUtils.success("操作成功",managerService.saveIndexMarketingPoster(imageUrl));
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     *取消发货
     * 取消物流平台的订单
     * */
    @PostMapping("cancelWuliuOrder")
    public JsonResult cancelWuliuOrder(@RequestParam("supplierId") int supplierId,@RequestParam("orderId") String orderId,@RequestParam("wlOrderId") String wlOrderId){
        try {
            int res=managerService.cancelWuliuOrder(supplierId,orderId,wlOrderId);
            if(res==0){
                return ResultUtils.success("操作成功",null);
            }else{
                return  ResultUtils.failure(101,"操作失败，请稍后再试");
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 批量获取运单号
     * */
    @PostMapping("batchGetTrackingNo")
    public JsonResult batchGetTrackingNo(@RequestParam("orderId") String orderId){
        try {
            managerService.batchGetTrackingNo(orderId);
            return ResultUtils.success("操作成功",null);
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 根据运单号获取
     * */
    @PostMapping("printWaybill")
    public JsonResult printWaybill(HttpServletRequest request,@RequestParam("trackingNo") String trackingNo ){
        try {
            String res=managerService.printWaybill(trackingNo,request.getRequestURL().toString());
            if (res==null){
                return  ResultUtils.failure(101,"获取电子面单异常，请稍后再试");
            }else{
                return ResultUtils.success("操作成功",res);
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 根据订单编号获取订单详情页信息
     * 新版
     * */
    @PostMapping("getOrderDesc")
    public JsonResult getOrderDesc(@RequestParam("orderId") String orderId ){
        try {
            OrderDescMa res=managerService.getOrderDesc(orderId);
            if (res==null){
                return  ResultUtils.failure(101,"获取订单详情失败，请稍后再试");
            }else{
                return ResultUtils.success("操作成功",res);
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 下载pdf文件
     * */
    @PostMapping("batchDownloadPdf")
    public JsonResult batchDownloadPdf(@RequestParam("orderId") String orderId){
        try {
            List<String> lists= managerService.batchDownloadPdf(orderId);
            if (lists==null){
                return  ResultUtils.failure(101,"无可下载的pdf文件");
            }else{
                return ResultUtils.success("操作成功",lists);
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }

    /**
     * 第一版首页需要数据
     * 未发货订单数量
     * 昨日出货数量
     * */
    @PostMapping("getIndexManagerData")
    public JsonResult getIndexManagerData(@RequestParam int accountType,@RequestParam int accountId){
        try {
            List<Integer> lists= managerService.getIndexManagerData(accountType,accountId);
            if (lists==null){
                return  ResultUtils.failure(101,"无数据");
            }else{
                return ResultUtils.success("操作成功",lists);
            }
        }catch (Exception e){
            e.printStackTrace();
            return  ResultUtils.failure(501,"系统异常");
        }
    }
}
